<template>
  <div>
    <Search :search="search" :reset="reset">
      <template v-slot:body>
        <el-form-item label="生产退料单号" prop="docno">
          <el-input v-model="query.docno" name="docno" clearable />
        </el-form-item>
        <el-form-item label="退料单类型" prop="doc_type">
          <el-input v-model="query.doc_type" name="doc_type" clearable />
        </el-form-item>
        <el-form-item label="退料单状态" prop="status">
          <el-select v-model="query.status"  placeholder="选择状态" clearable>
            <el-option v-for="item in DocStatusArr" :key="item.value" :label="item.label" :value="item.value" />
          </el-select>
        </el-form-item>
      </template>
    </Search>
    <div class="table-default">
      <!-- <Operate :show="open" /> -->
      <el-table :data="tableData" class="mt-3" v-loading="loading" border>
        <el-table-column label="生产退料单号" prop="docno" width="250" />
        <el-table-column label="单据状态" prop="status" width="110">
          <template #default="scope">
            <el-tag class="ml-2" type="warning" v-if="scope.row.status == 0">{{ DocStatus[scope.row.status] }}</el-tag>
            <el-tag class="ml-2" type="success" v-if="scope.row.status == 1">{{ DocStatus[scope.row.status] }}</el-tag>
            <el-tag class="ml-2" type="danger" v-if="scope.row.status == 2">{{ DocStatus[scope.row.status] }}</el-tag>
          </template>
        </el-table-column>
        <!-- <el-table-column label="退料单类型" prop="doc_type" width="120" /> -->
        <el-table-column label="创建者" prop="creator" />
        <el-table-column label="创建时间" prop="created_at" />
        <el-table-column label="更新时间" prop="updated_at" />
        <!-- <el-table-column label="单据状态" prop="doc_status" ></el-table-column> -->
        <el-table-column label="操作" width="100">
          <template #default="scope">
            <router-link :to="{ path: '/production/materialReturnDetail', query: { id: `${scope.row.id}` } }">
              <Show />
            </router-link>
            <!-- <Update @click="open(scope.row.id)" />
            <Destroy @click="destroy(api, scope.row.id)" /> -->
          </template>
        </el-table-column>
      </el-table>
      <Paginate />
    </div>

    <Dialog v-model="visible" :title="title" destroy-on-close>
      <Create @close="close(reset)" :primary="id" :api="api" />
    </Dialog>
  </div>
</template>

<script lang="ts" setup>
import { computed, onMounted, reactive, ref } from 'vue'
import Create from './create.vue'
import { useGetList } from '/admin/composables/curd/useGetList'
import { useDestroy } from '/admin/composables/curd/useDestroy'
import { useOpen } from '/admin/composables/curd/useOpen'
import http from '/admin/support/http'
import {setTableHeight} from '/admin/utils/setHeight.js'

const api = 'production/return/order'

const { data, query, search, reset, loading } = useGetList(api)
const { destroy, deleted } = useDestroy()
const { open, close, title, visible, id } = useOpen()

const tableData = computed(() => data.value?.data)

let DocStatus = reactive({})
let DocStatusArr = ref([])

let getDocStatus = () => {
  http.get(`options/DocStatus`).then(r => {
    DocStatusArr.value = r.data.data
    r.data.data.forEach((item, index) => {
      DocStatus[item.value] = item.label
    })
    console.log('单据状态', DocStatus)
  })
}

getDocStatus()

onMounted(() => {
  search()
  deleted(reset)
  setTableHeight('.table-default')

})
</script>
<style lang="css">
.el-table {
  height: 80%;
}
</style>